$(function () {
    var $userTableForm = $(".user-table-form");

    var settings = {
        url: ctx + "handle/handleList",
        pageSize: 10,
        queryParams: function (params) {
            return {
                pageSize: params.limit,
                pageNum: params.offset / params.limit + 1,
                id: $userTableForm.find("input[name='id']").val(),
                busCompany: $userTableForm.find("input[name='busCompany']").val(),
                paymentChannels: $userTableForm.find("select[name='selectPaymentChannels']").val(),
                complaintType: $userTableForm.find("select[name='selectComplaintType']").val(),
                processing: $userTableForm.find("select[name='selectProcessing']").val(),
                complaintChannels: $userTableForm.find("select[name='selectComplaintChannels']").val(),
                dutyDetermine: $userTableForm.find("select[name='selectDutyDetermine']").val(),
                startTime: $userTableForm.find("input[name='startTime']").val(),
                endTime: $userTableForm.find("input[name='endTime']").val(),
                startTime1: $userTableForm.find("input[name='startTime1']").val(),
                endTime1: $userTableForm.find("input[name='endTime1']").val(),
                handler: $userTableForm.find("input[name='handler']").val(),
                contactInformation: $userTableForm.find("input[name='contactInformation']").val()

            };
        },
        columns: [{
            field: 'id',
            title: '投诉信息编号',
        }, {
            field: 'acceptanceTime',
            title: '受理时间'
        }, {
            field: 'paymentChannels',
            title: '受理支付渠道'
        }, {
            field: 'complaintLine',
            title: '投诉线路'
        }, {
            field: 'contentsComplaints',
            title: '投诉内容',
            cellStyle:formatTableUnit,
            formatter:paramsMatter
        },{
            field: 'processingResults',
            title: '处理结果',
            cellStyle:formatTableUnit,
            formatter:paramsMatter
        }, {
            field: 'complaintType',
            title: '投诉类别'
        },{
            field: 'registrar',
            title: '登记人'
        },{
            field: 'processingTime',
            title: '处理时间'
        },{
            field: 'handler',
            title: '处理人'
        },{
            field: 'processing',
            title: '处理状态'
        },{
            field: 'remakes',
            title: '备注',
            cellStyle:formatTableUnit,
            formatter:paramsMatter
        },{
            title : '操作',
            field : 'id',
            align : 'center',
            width :  120 ,
            valign : 'middle',
            formatter : function(value,row,index){
                var d = '<button type="button" class="btn btn-primary" id="card_reading" data-toggle="modal"data-target="#noCard" onclick="load_data(\''+ row.id + '\')">修改</button> ';
                return d;
            }
        }/*,{
            title : '操作',
            field : 'id',
            align : 'center',
            width :  120 ,
            valign : 'middle',
            formatter : function(value,row,index){
                var d = '<button type="button" class="btn btn-primary" id="cancel" shiro:hasAnyPermissions="submission:cancelSubmission" onclick="cancel(\''+ row.id + '\')">撤销</button> ';
                return d;
            }
        }*/
        ]
    };
    $MB.initTable('userTable', settings);
});
function search() {
    $MB.refreshTable('userTable');
}

function cancel(x){
    var obj = new Object();
    obj.id = x;
    $.post(ctx+"submission/cancelSubmission",obj,function (r) {
        if (r.code !== 0) {
            $MB.n_danger(r.msg);
            $('#noCard').modal('hide')
            return;
        }else{
            $MB.n_success("投诉信息已撤销！");
            // print(r);
            $('#noCard').modal('hide')
            console.log(r)
            return;
        }
    });
};
//表格超出宽度鼠标悬停显示td内容
function paramsMatter(value,row,index, field) {
    var span=document.createElement('span');
    span.setAttribute('title',value);
    span.innerHTML = value;
    return span.outerHTML;
}
//td宽度以及内容超过宽度隐藏
function formatTableUnit(value, row, index) {
    return {
        css: {
            "white-space": 'nowrap',
            "text-overflow": 'ellipsis',
            "overflow": 'hidden',
            "max-width":"150px"
        }
    }
}